#!/usr/bin/env python
# -*- coding:utf-8 -*-
from django import forms
from teach import models
from stark.forms.forms import BootStrapModelForm


class CourseModelForm(BootStrapModelForm):
    class Meta:
        model = models.Course
        fields = "__all__"
        widgets = {
            'caption': forms.TextInput(attrs={'class': 'form-control'})
        }


class ModuleModelForm(BootStrapModelForm):
    class Meta:
        model = models.Module
        exclude = ['course', ]


class SimpleDailyModelForm(BootStrapModelForm):
    class Meta:
        model = models.Daily
        fields = ['title', 'sec_type', 'order']


class DailyModelForm(forms.ModelForm):
    class Meta:
        model = models.Daily
        fields = '__all__'
        widgets = {
            'module': forms.RadioSelect(),
            'sec_type': forms.RadioSelect(),
        }

    def __init__(self, cid, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for name, field in self.fields.items():
            if name == 'module':
                field.queryset = models.Module.objects.filter(course_id=cid)
                field.empty_label = None
                field.widget.attrs['class'] = 'form-radio'
            elif name == 'sec_type':
                field.empty_label = None
                field.widget.attrs['class'] = 'form-radio'
            else:
                field.widget.attrs['class'] = 'form-control'
